// 定义各种表单验证函数

const showErrorMsg = function (msg) {
	uni.showToast({
	    icon: 'none',
	    title: msg
	});
	return false;
}

const isValidPhone = function (phone) {
	var isnum = /^\d+$/.test(phone);
	if (phone.length != 11 || !isnum) {
	    return showErrorMsg('手机号必须为 11 位数字');
	}
	
	return true;
}

const isValidVcode = function (vcode) {
	if (vcode.length != 4) {
	    return showErrorMsg('验证码无效');
	}
	
	return true;
}

const isValidEmail = function (email) {
	//if (email.length < 3 || !~email.indexOf('@')) {

	if (email.length < 4) {
	    return showErrorMsg('邮箱地址不合法');
	} else {
		var re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
		if (!re.test(email)) {
		    return showErrorMsg('邮箱地址不合法2');
		}
	}
	
	return true;
}

const isValidPassword = function (password) {
	if (password.length < 6) {
	    return showErrorMsg('密码最短为 6 个字符');
	}
	
	return true;
}


export default {
	showErrorMsg,
	isValidPhone,
	isValidVcode,
	isValidEmail,
	isValidPassword
}
